<div>
    <div class="col-lg-12">
        <div class="panel panel-default">
            <!--<div class="panel-body">
                <div style="float: left;margin-top: -20px;">
                    <h3><a href="/product/create" class="btn btn-success pull-right">新增</a></h3>
                </div>
                <div class="align-right">
                    <button type="submit" onclick="javascript:search();return false;" class="btn btn-primary"><i class="fa fa-search"></i> 筛选</button>
                </div>
                <div class="col-md-2 align-right">
                    <input type="text" id="search_name_code" placeholder="请输入奖品名称" class="form-control" value="<?php /*echo $this->search_name; */?>" id="order_number">
                </div>
            </div>-->
            <div class="panel-body">
                <section id="no-more-tables">
                    <table class="table table-bordered table-striped table-condensed cf">
                        <thead class="cf">
                        <tr>
                            <td>序号</td>
                            <td>奖品图片</td>
                            <td>奖品名称</td>
                            <td>奖品描述</td>
                            <td>奖品数量</td>
                            <td>所属奖池</td>
                            <td>操作</td>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                        $i = ($this->now - 1) * $this->size+1;
                        foreach ($this->product_list as $product_info) { ?>
                            <tr>
                                <td data-title="id"><?php echo $i++; ?></td>
                                <td data-title="奖品图片">
                                    <div class="img-border" style="text-align: center">
                                        <img src="<?php echo $product_info['portrait'] ?>" width="50"/>
                                    </div>
                                </td>
                                <td data-title="奖品名称"><?php echo $product_info['name']; ?></td>
                                <td data-title="奖品描述"><?php echo $product_info['description']?></td>
                                <td data-title="奖品数量"><?php echo $product_info['total_num']?></td>
                                <td data-title="所属奖池"><?php echo \Orm\Product\ProductClass::getType($product_info['type']);?></td>
                                <td data-title="操作">
                                <a href="#" product_id="<?php echo $product_info['id'] ?>"
                                   onclick="deleteProduct(this)">删除</a></td>
                            </tr>
                        <?php } ?>
                        </tbody>
                    </table>
                    <?php echo $this->page ?>
                </section>
            </div>
        </div>
    </div>
</div>
<script>
    function search() {
        var search_name = $("#search_name").val();
        var query_string = '?';
        if (search_name !== '') {
            query_string += '&search_name=' + search_name;
        }
        query_string = query_string.substr(2, query_string.length);
        window.location.href = '/product/list?' + query_string;
    }
    /**
     * 删除奖品
     */
    function deleteProduct(e) {
        var product_id = $(e).attr('product_id');
        var index = layer.load(2, {
            shade: [0.5, '#fff'] //0.1透明度的白色背景
        });
        layer.confirm('确定删除奖品么？', function () {
            $.ajax({
                type: 'post',
                url: '/product/delete-product',
                data: {'product_id': product_id},
                dateType: 'json',
                success: function (response) {
                    if (response.code === 200) {
                        layer.alert(response.message);
                        window.location.reload();
                    } else {
                        layer.alert(response.message);
                    }
                }
            });
        });
        layer.close(index);
    }
</script>